package com.project.demo.job;

import com.project.demo.dao.HomestayInformationMapper;
import com.project.demo.service.HomestayInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务类
 * 周六周日翻倍
 * 5点后打七折
 */
@Component
public class TimeJob {
    @Autowired
    HomestayInformationMapper mapper;

    @Scheduled(cron = "0 0 1 * * SAT")
    public void doublePrice(){
        System.out.println("定时任务开始执行："+new Date());
        mapper.updateDailyPriceToDouble();
    }

    /**
     * 周一至周五下午5点以后执行日价打7折的任务
     */
    @Scheduled(cron = "0 0 17 * * MON-FRI")
    public void discountHomestayPrice() {
        int rows = mapper.discountDailyPrice();
        System.out.println("周一至周五下午5点后，打折了 " + rows + " 条民宿日价记录");
    }

    /**
     * 每天凌晨一点执行恢复日价的任务
     */
    @Scheduled(cron = "0 0 1 * *  MON-FRI")
    public void restoreHomestayPrice() {
        int rows = mapper.restoreDailyPrice();
        System.out.println("凌晨一点，恢复了 " + rows + " 条民宿日价记录");
    }

}
